package com.zztt.logmask.log4j;

import com.zztt.logmask.common.ConfigConst;
import com.zztt.logmask.common.utils.MaskHandleUtils;
import org.apache.log4j.Layout;
import org.apache.log4j.spi.LoggingEvent;

/**
 * 对PatternLayout的包装主要是为了将 日志脱敏的规则加入格式规则中
 */
public class CupdataZiconPatternLayout extends Layout{

    private Layout layout;

    public CupdataZiconPatternLayout(Layout layout){
        this.layout = layout;
    }

    @Override
    public String format(LoggingEvent event) {
        String message = layout.format(event);
        String level = event.getLevel().toString();
        return MaskHandleUtils.maskHandleMessage(ConfigConst.MASK_SWITCH,level,message);
    }

    @Override
    public boolean ignoresThrowable() {
        return layout.ignoresThrowable();
    }

    @Override
    public void activateOptions() {
        layout.activateOptions();
    }
}
